{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ipywidgets import interact\n",
    "import ipywidgets as widgets\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "import numpy as np\n",
    "plt.rcParams[\"figure.figsize\"] = (10,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "81390bb46e594df08192fdf28b281ae6",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=0.0, description='weight', max=5.0, min=-5.0), FloatSlider(value=0.0, …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def plot_relu_1d(weight, bias):\n",
    "    x = np.linspace(-5, 5, 32)\n",
    "    y = np.maximum(weight*x+bias, 0)\n",
    "    plt.plot(x, y)\n",
    "    \n",
    "interact(plot_relu_1d, weight=(-5., 5.), bias=(-5., 5.));"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ada9fa218d434904af5a75ac29a1389a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=0.0, description='weight1', max=5.0, min=-5.0), FloatSlider(value=0.0,…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def plot_relu_2d(weight1, weight2, bias):\n",
    "    x = np.linspace(-5, 5, 32)\n",
    "    y = np.linspace(-5, 5, 32)\n",
    "    xv, yv = np.meshgrid(x, y)\n",
    "    Z = np.maximum(weight1*xv+weight2*yv+bias, 0)\n",
    "    plt.imshow(Z)\n",
    "    plt.colorbar()\n",
    "    \n",
    "interact(plot_relu_2d, weight1=(-5., 5.), weight2=(-5., 5.), bias=(-5., 5.));"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "01fc5d3895b94f66af3232c8446e6c20",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=0.0, description='weight', max=5.0, min=-5.0), FloatSlider(value=0.0, …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def plot_mish_1d(weight, bias):\n",
    "    x = np.linspace(-5, 5, 32)\n",
    "    inputs = weight*x+bias\n",
    "    y = inputs * np.tanh(np.log(1+np.exp(inputs)))\n",
    "    plt.plot(x, y)\n",
    "    \n",
    "interact(plot_mish_1d, weight=(-5., 5.), bias=(-5., 5.));"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "91880ce6e4ea4bf7b935837607a31cad",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=0.0, description='weight1', max=5.0, min=-5.0), FloatSlider(value=0.0,…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "def plot_mish_2d(weight1, weight2, bias):\n",
    "    x = np.linspace(-5, 5, 32)\n",
    "    y = np.linspace(-5, 5, 32)\n",
    "    xv, yv = np.meshgrid(x, y)\n",
    "    inputs = weight1*xv+weight2*yv+bias\n",
    "    Z = inputs * np.tanh(np.log(1+np.exp(inputs)))\n",
    "    plt.imshow(Z)\n",
    "    plt.colorbar()\n",
    "    \n",
    "interact(plot_mish_2d, weight1=(-5., 5.), weight2=(-5., 5.), bias=(-5., 5.));"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
